<include file="Public/min-header"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
  <include file="Public/breadcrumb"/>
<style>
	  #fenlei_box{border: 1px solid #3297ff;position: absolute;width:450px;height:250px;overflow:hidden; z-index:9999;background:#fff;display:none;}
	  #fenlei_box li{list-style: none;color:#3297ff;text-align:left;margin-left:-20px;line-height: 32px;cursor: pointer;border-bottom:1px dashed}
	  #custom_box{border: 1px solid #3297ff;position: absolute;width:450px;height:250px;overflow:hidden; z-index:9999;background:#fff;display:none;}
	  #custom_box li{list-style: none;color:#3297ff;text-align:left;margin-left:-20px;line-height: 32px;cursor: pointer;border-bottom:1px dashed}
	  #teshu{display: none;color:red;}
</style>
    <section class="content">
        <!-- Main content --> 
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i>业绩任务基本信息</h3>
                </div>
                <div class="panel-body">

                    <!--表单数据-->
                    <form method="post" action="{:U('crm/addplan')}" id="order-add">
                        <div class="tab-pane" >
                            <table class="table table-bordered">
                                <tbody>
                                <tr>
                                    <td>业务员:</td>
                                    <td>
                                    <div class="form-group ">
                                        <div class="col-xs-4">
                                            <input name="user_name" id="user_name" class="form-control" value="{$data.company}" placeholder="业务员/手机号码搜索" oninput="kehu_sousuo($(this))" autocomplete="off"/>
                                			<ul id="fenlei_box">
                                			</ul>
                                			<input type="hidden" name="user_id" id="user_id" value="{$data.user_id}"/>
                                         </div>
                                     </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>任务开始时间:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-4">
	                                        <input name="start_time" id="start_time" value="{$data.start_time|date='Y-m-d',###}" class="form-control" placeholder="开始时间"/>	                                    
                                        </div>
                                    </div>    
                                    </td>
                                </tr>
                                <tr>
                                    <td>任务结束时间:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-4">
	                                        <input name="end_time" id="end_time" value="{$data.end_time|date='Y-m-d',###}" class="form-control" placeholder="结束时间"/>	                                    
                                        </div>
                                    </div>    
                                    </td>
                                </tr>
                                <tr>
                                    <td>计划业绩:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-4">
	                                        <input name="amount" id="amount" value="{$data.amount}" class="form-control" placeholder="计划业绩"/>	                                    
                                        </div>
                                    </div>    
                                    </td>
                                </tr>
                                <tr>
                                    <td>添加客户:</td>
                                    <td>
                                        <div class="form-group">
                                            <div class="col-xs-2">
	                                            <a class="btn btn-primary" href="javascript:void(0);" onclick="selectCustomer()" ><i class="fa fa-search"></i>添加客户</a>
                                            </div> 
                                            <div class="col-xs-2">
                                                <span id="err_goods" style="color:#F00; display:none;">请添加客户</span>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                               <tr>
                                    <td>客户明细:</td>
                                    <td> 
                                       <div class="form-group"> 
                                            <div class="col-xs-10" id="goods_td">
                                                <table class="table table-bordered" id="myTable">
                                                    <?php
                    								if(strlen($data['customer_id_arr']) > 0){
                    								?>
                    								<thead>
                            			            <tr>
                            			                <td class="text-left">客户名称</td>            
                            			                <td class="text-left">姓名</td>
                            			                <td class="text-left">电话</td>
                            			             <td class="text-left" id="dis" style="display: none;">
                            			                <td class="text-left">操作</td>
                            			            </tr>
                            			            </thead>
                            			            <tbody>
                            			                <volist name="custom_data" id="value" >
                                                            <tr>
                                                                <td class="text-left">{$value.company}</td>
                                                                <td class="text-left">{$value.nickname}</td>
                                                                <td class="text-left">{$value.mobile}</td>
                                                                <td class="text-left" id="dis" style="display: none;">
                                                                    <input type="text" name="cunstomer_id[{$value.user_id}]" value="{$value.user_id}" class="input-sm" style="" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                                                    
                                                                </td>
                                                                <td><a href="javascript:" onclick="javascript:$(this).parent().parent().remove();">删除</a></td>
                                                            </tr>
                                                        </volist>
                            			            </tbody>
                    								<?php
                    								}
                    								?>
												</table>
                                            </div>
	                                   </div>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td>选择业绩对应的产品分类:</td>
                                    <td>
                                        <div class="form-group">
                                            <div class="col-xs-2">
	                                            <a class="btn btn-primary" href="javascript:void(0);" onclick="selectGoods()" ><i class="fa fa-search"></i>添加产品分类</a>
                                            </div> 
                                            <div class="col-xs-2">
                                                <span id="err_goodss" style="color:#F00; display:none;">请添加产品分类</span>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td>产品分类明细:</td>
                                    <td> 
                                       <div class="form-group"> 
                                            <div class="col-xs-10" id="category_td">
                                                <table class="table table-bordered" id="myTable">
                                                    <?php
                    								if(strlen($data['category_id_arr']) > 0){
                    								?>
                    								<thead>
                            			            <tr>
                            			                <td class="text-left">产品分类</td>            
                            			             <td class="text-left" id="dis" style="display: none;">
                            			                <td class="text-left">操作</td>
                            			            </tr>
                            			            </thead>
                            			            <tbody>
                            			                <volist name="category_data" id="value" >
                                                            <tr>
                                                                <td class="text-left">{$value.name}</td>
                                                                <td class="text-left" id="dis" style="display: none;">
                                                                    <input type="text" name="category_id[{$value.id}]" value="{$value.id}" class="input-sm" style="" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                                                    
                                                                </td>
                                                                <td><a href="javascript:" onclick="javascript:$(this).parent().parent().remove();">删除</a></td>
                                                            </tr>
                                                        </volist>
                            			            </tbody>
                    								<?php
                    								}
                    								?>
												</table>
                                            </div>
	                                   </div>
                                    </td>
                                </tr>
                                
                                
                                
                                <tr>
                                    <td>选择排除的业绩产品分类:</td>
                                    <td>
                                        <div class="form-group">
                                            <div class="col-xs-2">
	                                            <a class="btn btn-primary" href="javascript:void(0);" onclick="selectexcludeGoods()" ><i class="fa fa-search"></i>添加产品分类</a>
                                            </div> 
                                            <div class="col-xs-2">
                                                <span id="err_goodss" style="color:#F00; display:none;">请选择排除的产品分类</span>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td>排除的产品分类明细:</td>
                                    <td> 
                                       <div class="form-group"> 
                                            <div class="col-xs-10" id="excludecategory_td">
                                                <table class="table table-bordered" id="myTable">
                                                    <?php
                    								if(strlen($data['excludecategory_id_arr']) > 0){
                    								?>
                    								<thead>
                            			            <tr>
                            			                <td class="text-left">产品分类</td>            
                            			             <td class="text-left" id="dis" style="display: none;">
                            			                <td class="text-left">操作</td>
                            			            </tr>
                            			            </thead>
                            			            <tbody>
                            			                <volist name="excludecategory_data" id="value" >
                                                            <tr>
                                                                <td class="text-left">{$value.name}</td>
                                                                <td class="text-left" id="dis" style="display: none;">
                                                                    <input type="text" name="excludecategory_id[{$value.id}]" value="{$value.id}" class="input-sm" style="" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                                                    
                                                                </td>
                                                                <td><a href="javascript:" onclick="javascript:$(this).parent().parent().remove();">删除</a></td>
                                                            </tr>
                                                        </volist>
                            			            </tbody>
                    								<?php
                    								}
                    								?>
												</table>
                                            </div>
	                                   </div>
                                    </td>
                                </tr>
                                
                                </tbody>
                                </table>
                        </div>
                        <input type="hidden" name="id" value="{$data.id}">
                        <button class="btn btn-info" type="button" onclick="checkSubmit()">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                            保存
                        </button>
                    </form>
<!--以下是在线编辑器 代码 -->
<script type="text/javascript">
    /*
	 * 在线编辑器相 关配置 js
	 *  参考 地址 http://fex.baidu.com/ueditor/
	 */
    // 上传商品相册回调函数
    function call_back2(paths){
            $(".goods_xc").find('img').attr('src',paths);// 修改他的图片路径
            $(".goods_xc").find('a:eq(1)').attr('onclick',"ClearPicArr2(this)").text('删除');
            $(".goods_xc").find('#fujian').val('{$myurl}'+paths); // 设置隐藏域 要提交的值
    }
	    function ClearPicArr2(obj)
	    {
	        $(obj).parent().find('img').attr('src','/Public/images/add-button.jpg'); // 删除完服务器的, 再删除 html上的图片
			$(".goods_xc").find('#fujian').val('');
		}
	
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "https://{:$_SERVER['HTTP_HOST']}{$URL_upload}";
    var URL_fileUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_fileUp}";
    var URL_scrawlUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_scrawlUp}";
    var URL_getRemoteImage = "http://{:$_SERVER['HTTP_HOST']}{$URL_getRemoteImage}";
    var URL_imageManager = "http://{:$_SERVER['HTTP_HOST']}{$URL_imageManager}";
    var URL_imageUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_imageUp}";
    var URL_getMovie = "http://{:$_SERVER['HTTP_HOST']}{$URL_getMovie}";
    var URL_home = "http://{:$_SERVER['HTTP_HOST']}{$URL_home}";
</script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js  中
        var options = {
            zIndex: 999,
            initialFrameWidth: "95%", //初化宽度
            initialFrameHeight: 220, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign'
            , //允许的最大字符数 'fullscreen',
            pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
            autoHeightEnabled: true,
        	toolbars: [
                   ['fullscreen', 'source', '|', 'undo', 'redo',
                       '|', 'bold', 'italic', 'underline', 'fontborder',
                       'strikethrough', 'superscript', 'subscript',
                       'removeformat', 'formatmatch', 'autotypeset',
                       'blockquote', 'pasteplain', '|', 'forecolor',
                       'backcolor', 'insertorderedlist',
                       'insertunorderedlist','selectall', 'cleardoc']
               ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("user_note");  //  指定 textarea 的  id 为 goods_content
    }); 
	
						$('input:radio').click(function(){
						    var zhi=$(this).val();
							$("span[id^='err_']").each(function(){
								$(this).hide();
							});
							$('#add_user').hide(100);
							if(zhi==1){
								//$('#address').removeAttr('readonly');$('#address').val('');
								//$('#mobile').removeAttr('readonly');$('#mobile').val('');
								$('#biaoshi_xian').removeAttr('readonly');$('#biaoshi_xian').val('');$('#user_name').val('');$('body #teshu').show(200);$('body #dai').hide(200);
							}else{
								//$('#address').attr('readonly','readonly');
								//$('#mobile').attr('readonly','readonly');
								$('#biaoshi_xian').attr('readonly','readonly');
								$('body #teshu').hide(100);$('body #dai').show(200);
							}
							
						  });
						  
                        function checkSubmit()
						{
							var dai_type=$("input[type='radio']:checked").val();
							$("span[id^='err_']").each(function(){
								$(this).hide();
							});
							
							//if(dai_type=='1')
								//($.trim($('#user_note').val()) == '') && $('#err_user_note').show();
	
						   ($.trim($('#order_sn').val()) == '') && $('#err_order_sn').show();
						   ($.trim($('#biaoshi_xian').val()) == '') && $('#err_biaoshi_xian').show();
						   ($.trim($('#biaoqian').val()) == '0') && $('#err_biaoqian').show();
						   //($.trim($('#mobile').val()) == '') && $('#err_mobile').show();
						   if(dai_type=='0')
						   ($("input[name^='goods_id']").length ==0) && $('#err_goods').show();
						   
						   if($("span[id^='err_']:visible").length > 0 ) 
						      return false;

							$('#order-add').submit();
						}
                    </script>
                </div>
            </div>
            
        </div>    <!-- /.content -->
    </section>
</div>
<script>
function custom_sousuo(obj)
	{
	    var value = obj.val();
		if($.trim(custom_name) == '')
			return false;
		
		var dai_type=$("input[type='radio']:checked").val();
	    $.ajax({
	       type : "POST",
	       url:"/index.php?m=admin&c=crm&a=search_customer",//+tab,
	       data :{search_key:value},
	        success: function(data){
				data=JSON.parse(data);
					 if(data.code=='200'){
						$('#custom_box').show(200);
						$('#add_user').hide(100);
						$('#custom_box').html(data.selects);
					 }else{
						$('#custom_box').hide(100);
						if(dai_type==1)
						$('#add_user').show(200);
						
						$('#custom_box').html('');
					 }
	        }
	    });
	}
  
	function kehu_sousuo(obj)
	{
	    var value = obj.val();
		if($.trim(user_name) == '')
			return false;
		
		var dai_type=$("input[type='radio']:checked").val();
	    $.ajax({
	       type : "POST",
	       url:"/index.php?m=admin&c=crm&a=search_user",//+tab,
	       data :{search_key:value},
	        success: function(data){
				data=JSON.parse(data);
					 if(data.code=='200'){
						$('#fenlei_box').show(200);
						$('#add_user').hide(100);
						$('#fenlei_box').html(data.selects);
					 }else{
						$('#fenlei_box').hide(100);
						if(dai_type==1)
						$('#add_user').show(200);
						
						$('#fenlei_box').html('');
					 }
	        }
	    });
	}
function data_pick(id){
    var myDate = new Date();
    $('#'+id).daterangepicker({
    	format:"YYYY-MM-DD",
        singleDatePicker: true,
        showDropdowns: true,
        minDate:myDate.getFullYear()+'-'+myDate.getMonth()+'-'+myDate.getDate(),
        maxDate:'2030-01-01',
		timePicker : true, //是否显示小时和分钟  
        timePickerIncrement:1,//time选择递增数
		timePicker12Hour : false, //是否使用12小时制来显示时间 		
        locale : {
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
            firstDay : 1
        }
    });
}
    /* 用户客户选择 layer.msg('该用户不是本商城审核会员！不能代其下单。', {icon: 5});*/
    $(document).ready(function(){
		$("body").on("click", function() {
			$('#fenlei_box').hide(100);
			$('#custom_box').hide(100);
		});
		data_pick('start_time');
		data_pick('end_time');
		$("#fenlei_box").on("click","li", function() {
			var user_id=$(this).attr('rel'),
				company=$(this).attr('title');

			$('#user_name').val(company);
			$('#user_id').val(user_id);
		});
	    $("#custom_box").on("click","li", function() {
			var user_id=$(this).attr('rel'),
				company=$(this).attr('title');
			$('#custom_name').val(company);
			$('#custom_id').val(user_id);
		});
	$("#goods_td").on("change","input", function() {
		tongji();
	});
	
	$("#goods_td").on("click","a", function() {
		$(this).parent().parent().remove();
		tongji();
    })
	})
// 选择客户
function selectCustomer(){
    var url = "{:U('Admin/Crm/search_customers')}";
    layer.open({
        type: 2,
        title: '选择客户',
        shadeClose: true,
        shade: 0.8,
        area: ['80%', '80%'],
        content: url, 
    });
}
    
 	// 选择商品分类
	function selectGoods(){
        var url = "{:U('Admin/Crm/search_goods')}";
        layer.open({
            type: 2,
            title: '选择商品分类',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '80%'],
            content: url, 
        });
    }    
 
	// 排除业绩商品分类
	function selectexcludeGoods(){
        var url = "{:U('Admin/Crm/selectexcludeGoods')}";
        layer.open({
            type: 2,
            title: '选择商品分类',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '80%'],
            content: url, 
        });
    }    
	
// 选择商品返回
function call_back(table_html)
{ 	
	//$('#goods_td').empty().html('<table class="table table-bordered">'+table_html+'</table>');
	//table_html=table_html.replaceAll("javascript:$(this).parent().parent().remove();","");console.log(table_html);
	$('#goods_td .table-bordered').append(table_html);
    $('#goods_td tr').find('td:eq(3)').hide();
    $('#goods_td tr').find('th:eq(3)').hide();
    // let table = document.getElementById('myTable');
    // let columnIndex = 3; // 删除第4列，索引从0开始
    // for (let i = 0; i < table.rows.length; i++) {
    //     let row = table.rows[i];
    //     if (row.cells.length > columnIndex) {
    //         //row.deleteCell(columnIndex);
            
    //         row.cells[i].style.display = 'none';
    //     }
    // }
	layer.closeAll('iframe');//tongji();
}

//选择商品分类返回
function call_back_goods(table_html)
{ 	
	$('#category_td .table-bordered').append(table_html);
    $('#category_td tr').find('td:eq(1)').hide();
    $('#category_td tr').find('th:eq(1)').hide();
	layer.closeAll('iframe');//tongji();
}

//选择商品分类返回
function call_back_excludegoods(table_html)
{ 	
	$('#excludecategory_td .table-bordered').append(table_html);
    $('#excludecategory_td tr').find('td:eq(1)').hide();
    $('#excludecategory_td tr').find('th:eq(1)').hide();
	layer.closeAll('iframe');//tongji();
}
function tongji(){
	var heji=0;
	$("#goods_td tbody tr").each(function(){
		var price=$(this).find('td').eq(1).text();
		var num=$(this).find('input').val();
		if(price!=''){
			price=parseFloat(price);num=parseFloat(num);
			heji=heji+(price*num);
		}
	  });
	  $('#z_jine').val(heji.toFixed(3));
	 //return heji.toFixed(3);
}
</script>
</body>
</html>